<?php
/**
 * Description:  门店留资
 * Created by PhpStorm.
 * User: 玉坤
 * Date: 2021/9/9
 * Time: 14:04
 */


ini_set('display_errors', 1);
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED);
ini_set('memory_limit', '1024M');

require_once '/data/wwwroot/g_vendor/autoload.php';


$err_json = '{"28476":{"name":"南山区","code":440305,"新":"黑龙江,鹤岗,南山区","原":"广东,深圳,南山区","id":28476},"28486":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28486},"28504":{"name":"桥西区","code":130703,"新":"河北,张家口,桥西区","原":"河北,石家庄,桥西区","id":28504},"28506":{"name":"桥西区","code":130703,"新":"河北,张家口,桥西区","原":"河北,石家庄,桥西区","id":28506},"28510":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28510},"28511":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28511},"28512":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28512},"28522":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28522},"28527":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28527},"28529":{"name":"新华区","code":410402,"新":"河南,平顶山,新华区","原":"河北,石家庄,新华区","id":28529},"28531":{"name":"","code":"","新":"","原":"内蒙古,呼和浩特,","id":28531},"28538":{"name":"桥西区","code":130703,"新":"河北,张家口,桥西区","原":"河北,邢台,桥西区","id":28538},"28546":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28546},"28547":{"name":"通州区","code":320612,"新":"江苏,南通,通州区","原":"北京,通州区","id":28547},"28551":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28551},"28558":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28558},"28559":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28559},"28567":{"name":"桥西区","code":130703,"新":"河北,张家口,桥西区","原":"河北,石家庄,桥西区","id":28567},"28573":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28573},"28578":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28578},"28579":{"name":"朝阳区","code":220104,"新":"吉林,长春,朝阳区","原":"北京,朝阳区","id":28579}}';
$success_json = '{"28463":{"name":"柯城区","code":330802,"新":"浙江,衢州,柯城区","原":"浙江,衢州,柯城区","id":28463},"28455":{"name":"长沙县","code":430121,"新":"湖南,长沙,长沙县","原":"湖南,长沙,长沙县","id":28455},"28465":{"name":"雁塔区","code":610113,"新":"陕西,西安,雁塔区","原":"陕西,西安,雁塔区","id":28465},"28469":{"name":"泾阳县","code":610423,"新":"陕西,咸阳,泾阳县","原":"陕西,咸阳,泾阳县","id":28469},"28471":{"name":"道里区","code":230102,"新":"黑龙江,哈尔滨,道里区","原":"黑龙江,哈尔滨,道里区","id":28471},"28472":{"name":"道外区","code":230104,"新":"黑龙江,哈尔滨,道外区","原":"黑龙江,哈尔滨,道外区","id":28472},"28474":{"name":"南沙区","code":440115,"新":"广东,广州,南沙区","原":"广东,广州,南沙区","id":28474},"28475":{"name":"南沙区","code":440115,"新":"广东,广州,南沙区","原":"广东,广州,南沙区","id":28475},"28477":{"name":"嘉定区","code":310114,"新":"上海,嘉定区","原":"上海,嘉定区","id":28477},"28478":{"name":"秀洲区","code":330411,"新":"浙江,嘉兴,秀洲区","原":"浙江,嘉兴,秀洲区","id":28478},"28481":{"name":"云岩区","code":520103,"新":"贵州,贵阳,云岩区","原":"贵州,贵阳,云岩区","id":28481},"28482":{"name":"乐昌市","code":440281,"新":"广东,韶关,乐昌市","原":"广东,韶关,乐昌市","id":28482},"28483":{"name":"武昌区","code":420106,"新":"湖北,武汉,武昌区","原":"湖北,武汉,武昌区","id":28483},"28484":{"name":"顺德区","code":440606,"新":"广东,佛山,顺德区","原":"广东,佛山,顺德区","id":28484},"28485":{"name":"渝北区","code":500112,"新":"重庆,渝北区","原":"重庆,渝北区","id":28485},"28487":{"name":"楚雄市","code":532301,"新":"云南,楚雄彝族自治州,楚雄市","原":"云南,楚雄彝族自治州,楚雄市","id":28487},"28489":{"name":"新北区","code":320411,"新":"江苏,常州,新北区","原":"江苏,常州,新北区","id":28489},"28490":{"name":"楚雄市","code":532301,"新":"云南,楚雄彝族自治州,楚雄市","原":"云南,楚雄彝族自治州,楚雄市","id":28490},"28491":{"name":"南沙区","code":440115,"新":"广东,广州,南沙区","原":"广东,广州,南沙区","id":28491},"28492":{"name":"法库县","code":210124,"新":"辽宁,沈阳,法库县","原":"辽宁,沈阳,法库县","id":28492},"28493":{"name":"太和区","code":210711,"新":"辽宁,锦州,太和区","原":"辽宁,锦州,太和区","id":28493},"28494":{"name":"钦北区","code":450703,"新":"广西,钦州,钦北区","原":"广西,钦州,钦北区","id":28494},"28495":{"name":"嘉定区","code":310114,"新":"上海,嘉定区","原":"上海,嘉定区","id":28495},"28496":{"name":"天台县","code":331023,"新":"浙江,台州,天台县","原":"浙江,台州,天台县","id":28496},"28497":{"name":"南沙区","code":440115,"新":"广东,广州,南沙区","原":"广东,广州,南沙区","id":28497},"28498":{"name":"青龙满族自治县","code":130321,"新":"河北,秦皇岛,青龙满族自治县","原":"河北,秦皇岛,青龙满族自治县","id":28498},"28499":{"name":"六合区","code":320116,"新":"江苏,南京,六合区","原":"江苏,南京,六合区","id":28499},"28500":{"name":"福山区","code":370611,"新":"山东,烟台,福山区","原":"山东,烟台,福山区","id":28500},"28501":{"name":"槐荫区","code":370104,"新":"山东,济南,槐荫区","原":"山东,济南,槐荫区","id":28501},"28502":{"name":"青龙满族自治县","code":130321,"新":"河北,秦皇岛,青龙满族自治县","原":"河北,秦皇岛,青龙满族自治县","id":28502},"28503":{"name":"新北区","code":320411,"新":"江苏,常州,新北区","原":"江苏,常州,新北区","id":28503},"28505":{"name":"鹿泉区","code":130110,"新":"河北,石家庄,鹿泉区","原":"河北,石家庄,鹿泉区","id":28505},"28507":{"name":"鹿泉区","code":130110,"新":"河北,石家庄,鹿泉区","原":"河北,石家庄,鹿泉区","id":28507},"28508":{"name":"灞桥区","code":610111,"新":"陕西,西安,灞桥区","原":"陕西,西安,灞桥区","id":28508},"28509":{"name":"苏州工业园区","code":320571,"新":"江苏,苏州,苏州工业园区","原":"江苏,苏州,苏州工业园区","id":28509},"28513":{"name":"六合区","code":320116,"新":"江苏,南京,六合区","原":"江苏,南京,六合区","id":28513},"28514":{"name":"公主岭市","code":220381,"新":"吉林,四平,公主岭市","原":"吉林,四平,公主岭市","id":28514},"28516":{"name":"晋江市","code":350582,"新":"福建,泉州,晋江市","原":"福建,泉州,晋江市","id":28516},"28518":{"name":"郫都区","code":510117,"新":"四川,成都,郫都区","原":"四川,成都,郫都区","id":28518},"28519":{"name":"六合区","code":320116,"新":"江苏,南京,六合区","原":"江苏,南京,六合区","id":28519},"28521":{"name":"闵行区","code":310112,"新":"上海,闵行区","原":"上海,闵行区","id":28521},"28523":{"name":"南湖区","code":330402,"新":"浙江,嘉兴,南湖区","原":"浙江,嘉兴,南湖区","id":28523},"28524":{"name":"包河区","code":340111,"新":"安徽,合肥,包河区","原":"安徽,合肥,包河区","id":28524},"28525":{"name":"禹会区","code":340304,"新":"安徽,蚌埠,禹会区","原":"安徽,蚌埠,禹会区","id":28525},"28526":{"name":"虎丘区","code":320505,"新":"江苏,苏州,虎丘区","原":"江苏,苏州,虎丘区","id":28526},"28530":{"name":"黄浦区","code":310101,"新":"上海,黄浦区","原":"上海,黄浦区","id":28530},"28532":{"name":"洪山区","code":420111,"新":"湖北,武汉,洪山区","原":"湖北,武汉,洪山区","id":28532},"28533":{"name":"金州区","code":210213,"新":"辽宁,大连,金州区","原":"辽宁,大连,金州区","id":28533},"28534":{"name":"建邺区","code":320105,"新":"江苏,南京,建邺区","原":"江苏,南京,建邺区","id":28534},"28535":{"name":"宽城区","code":220103,"新":"吉林,长春,宽城区","原":"吉林,长春,宽城区","id":28535},"28536":{"name":"苏州工业园区","code":320571,"新":"江苏,苏州,苏州工业园区","原":"江苏,苏州,苏州工业园区","id":28536},"28537":{"name":"青山湖区","code":360111,"新":"江西,南昌,青山湖区","原":"江西,南昌,青山湖区","id":28537},"28540":{"name":"荔湾区","code":440103,"新":"广东,广州,荔湾区","原":"广东,广州,荔湾区","id":28540},"28541":{"name":"溧水区","code":320117,"新":"江苏,南京,溧水区","原":"江苏,南京,溧水区","id":28541},"28543":{"name":"江阳区","code":510502,"新":"四川,泸州,江阳区","原":"四川,泸州,江阳区","id":28543},"28544":{"name":"资中县","code":511025,"新":"四川,内江,资中县","原":"四川,内江,资中县","id":28544},"28549":{"name":"江宁区","code":320115,"新":"江苏,南京,江宁区","原":"江苏,南京,江宁区","id":28549},"28550":{"name":"西青区","code":120111,"新":"天津,西青区","原":"天津,西青区","id":28550},"28553":{"name":"六合区","code":320116,"新":"江苏,南京,六合区","原":"江苏,南京,六合区","id":28553},"28554":{"name":"京口区","code":321102,"新":"江苏,镇江,京口区","原":"江苏,镇江,京口区","id":28554},"28557":{"name":"长宁区","code":310105,"新":"上海,长宁区","原":"上海,长宁区","id":28557},"28560":{"name":"丛台区","code":130403,"新":"河北,邯郸,丛台区","原":"河北,邯郸,丛台区","id":28560},"28561":{"name":"屯溪区","code":341002,"新":"安徽,黄山,屯溪区","原":"安徽,黄山,屯溪区","id":28561},"28562":{"name":"硚口区","code":420104,"新":"湖北,武汉,硚口区","原":"湖北,武汉,硚口区","id":28562},"28563":{"name":"港南区","code":450803,"新":"广西,贵港,港南区","原":"广西,贵港,港南区","id":28563},"28564":{"name":"济源市","code":419001,"新":"河南,济源市","原":"河南,济源市","id":28564},"28565":{"name":"闵行区","code":310112,"新":"上海,闵行区","原":"上海,闵行区","id":28565},"28568":{"name":"双流区","code":510116,"新":"四川,成都,双流区","原":"四川,成都,双流区","id":28568},"28569":{"name":"九台区","code":220113,"新":"吉林,长春,九台区","原":"吉林,长春,九台区","id":28569},"28570":{"name":"广信区","code":361104,"新":"江西,上饶,广信区","原":"江西,上饶,广信区","id":28570},"28571":{"name":"铁西区","code":210106,"新":"辽宁,沈阳,铁西区","原":"辽宁,沈阳,铁西区","id":28571},"28572":{"name":"连城县","code":350825,"新":"福建,龙岩,连城县","原":"福建,龙岩,连城县","id":28572},"28574":{"name":"嘉峪关","code":620200,"新":"甘肃,嘉峪关","原":"甘肃,嘉峪关","id":28574},"28575":{"name":"余杭区","code":330110,"新":"浙江,杭州,余杭区","原":"浙江,杭州,余杭区","id":28575},"28577":{"name":"天河区","code":440106,"新":"广东,广州,天河区","原":"广东,广州,天河区","id":28577},"28580":{"name":"花地玛堂区","code":820001,"新":"澳门,花地玛堂区","原":"澳门,花地玛堂区","id":28580},"28581":{"name":"昌平区","code":110114,"新":"北京,昌平区","原":"北京,昌平区","id":28581},"28582":{"name":"萧山区","code":330109,"新":"浙江,杭州,萧山区","原":"浙江,杭州,萧山区","id":28582},"28583":{"name":"涪城区","code":510703,"新":"四川,绵阳,涪城区","原":"四川,绵阳,涪城区","id":28583},"28585":{"name":"丰台区","code":110106,"新":"北京,丰台区","原":"北京,丰台区","id":28585},"28586":{"name":"来安县","code":341122,"新":"安徽,滁州,来安县","原":"安徽,滁州,来安县","id":28586},"28587":{"name":"雨花区","code":430111,"新":"湖南,长沙,雨花区","原":"湖南,长沙,雨花区","id":28587},"28588":{"name":"禅城区","code":440604,"新":"广东,佛山,禅城区","原":"广东,佛山,禅城区","id":28588},"28589":{"name":"回民区","code":150103,"新":"内蒙古,呼和浩特,回民区","原":"内蒙古,呼和浩特,回民区","id":28589},"28590":{"name":"坪山区","code":440310,"新":"广东,深圳,坪山区","原":"广东,深圳,坪山区","id":28590},"28591":{"name":"坪山区","code":440310,"新":"广东,深圳,坪山区","原":"广东,深圳,坪山区","id":28591},"28592":{"name":"任城区","code":370811,"新":"山东,济宁,任城区","原":"山东,济宁,任城区","id":28592},"28593":{"name":"建湖县","code":320925,"新":"江苏,盐城,建湖县","原":"江苏,盐城,建湖县","id":28593},"28594":{"name":"三河市","code":131082,"新":"河北,廊坊,三河市","原":"河北,廊坊,三河市","id":28594},"28595":{"name":"镇海区","code":330211,"新":"浙江,宁波,镇海区","原":"浙江,宁波,镇海区","id":28595},"28596":{"name":"蜀山区","code":340104,"新":"安徽,合肥,蜀山区","原":"安徽,合肥,蜀山区","id":28596},"28597":{"name":"浦东新区","code":310115,"新":"上海,浦东新区","原":"上海,浦东新区","id":28597},"28598":{"name":"濂溪区","code":360402,"新":"江西,九江,濂溪区","原":"江西,九江,濂溪区","id":28598},"28599":{"name":"兴县","code":141123,"新":"山西,吕梁,兴县","原":"山西,吕梁,兴县","id":28599}}';





$aaa = [
    28476 => 440305,
    28486 => 110105,
    28504 => 130104,
    28506 => 130104,
    28510 => 110105,
    28511 => 110105,
    28512 => 110105,
    28522 => 110105,
    28527 => 110105,
    28546 => 110105,
    28551 => 110105,
    28558 => 110105,
    28559 => 110105,
    28573 => 110105,
    28578 => 110105,
    28579 => 110105,
    28529 => 130105,
    28531 => 150103,
    28538 => 130503,
    28547 => 110112,
    28567 => 130104
];

$page = 1;
foreach ($aaa as $id => $code) {
    $data['area_code'] = $code;
    $where['id'] = $id;
    echo $page++ . "\n";
    \Biz\model\trade\UserAddress::update($data, $where);
}

die;


$arr = [
    28463 => "浙江,衢州,柯城区",
    28455 => "湖南,长沙,长沙县",
    28465 => "陕西,西安,雁塔区",
    28469 => "陕西,咸阳,泾阳县",
    28471 => "黑龙江,哈尔滨,道里区",
    28472 => "黑龙江,哈尔滨,道外区",
    28474 => "广东,广州,南沙区",
    28475 => "广东,广州,南沙区",
    28476 => "广东,深圳,南山区",
    28477 => "上海,嘉定区",
    28478 => "浙江,嘉兴,秀洲区",
    28481 => "贵州,贵阳,云岩区",
    28482 => "广东,韶关,乐昌市",
    28483 => "湖北,武汉,武昌区",
    28484 => "广东,佛山,顺德区",
    28485 => "重庆,渝北区",
    28486 => "北京,朝阳区",
    28487 => "云南,楚雄彝族自治州,楚雄市",
    28489 => "江苏,常州,新北区",
    28490 => "云南,楚雄彝族自治州,楚雄市",
    28491 => "广东,广州,南沙区",
    28492 => "辽宁,沈阳,法库县",
    28493 => "辽宁,锦州,太和区",
    28494 => "广西,钦州,钦北区",
    28495 => "上海,嘉定区",
    28496 => "浙江,台州,天台县",
    28497 => "广东,广州,南沙区",
    28498 => "河北,秦皇岛,青龙满族自治县",
    28499 => "江苏,南京,六合区",
    28500 => "山东,烟台,福山区",
    28501 => "山东,济南,槐荫区",
    28502 => "河北,秦皇岛,青龙满族自治县",
    28503 => "江苏,常州,新北区",
    28504 => "河北,石家庄,桥西区",
    28505 => "河北,石家庄,鹿泉区",
    28506 => "河北,石家庄,桥西区",
    28507 => "河北,石家庄,鹿泉区",
    28508 => "陕西,西安,灞桥区",
    28509 => "江苏,苏州,苏州工业园区",
    28510 => "北京,朝阳区",
    28511 => "北京,朝阳区",
    28512 => "北京,朝阳区",
    28513 => "江苏,南京,六合区",
    28514 => "吉林,四平,公主岭市",
    28516 => "福建,泉州,晋江市",
    28518 => "四川,成都,郫都区",
    28519 => "江苏,南京,六合区",
    28521 => "上海,闵行区",
    28522 => "北京,朝阳区",
    28523 => "浙江,嘉兴,南湖区",
    28524 => "安徽,合肥,包河区",
    28525 => "安徽,蚌埠,禹会区",
    28526 => "江苏,苏州,虎丘区",
    28527 => "北京,朝阳区",
    28529 => "河北,石家庄,新华区",
    28530 => "上海,黄浦区",
    28531 => "内蒙古,呼和浩特,",
    28532 => "湖北,武汉,洪山区",
    28533 => "辽宁,大连,金州区",
    28534 => "江苏,南京,建邺区",
    28535 => "吉林,长春,宽城区",
    28536 => "江苏,苏州,苏州工业园区",
    28537 => "江西,南昌,青山湖区",
    28538 => "河北,邢台,桥西区",
    28540 => "广东,广州,荔湾区",
    28541 => "江苏,南京,溧水区",
    28543 => "四川,泸州,江阳区",
    28544 => "四川,内江,资中县",
    28546 => "北京,朝阳区",
    28547 => "北京,通州区",
    28549 => "江苏,南京,江宁区",
    28550 => "天津,西青区",
    28551 => "北京,朝阳区",
    28553 => "江苏,南京,六合区",
    28554 => "江苏,镇江,京口区",
    28557 => "上海,长宁区",
    28558 => "北京,朝阳区",
    28559 => "北京,朝阳区",
    28560 => "河北,邯郸,丛台区",
    28561 => "安徽,黄山,屯溪区",
    28562 => "湖北,武汉,硚口区",
    28563 => "广西,贵港,港南区",
    28564 => "河南,济源市",
    28565 => "上海,闵行区",
    28567 => "河北,石家庄,桥西区",
    28568 => "四川,成都,双流区",
    28569 => "吉林,长春,九台区",
    28570 => "江西,上饶,广信区",
    28571 => "辽宁,沈阳,铁西区",
    28572 => "福建,龙岩,连城县",
    28573 => "北京,朝阳区",
    28574 => "甘肃,嘉峪关",
    28575 => "浙江,杭州,余杭区",
    28577 => "广东,广州,天河区",
    28578 => "北京,朝阳区",
    28579 => "北京,朝阳区",
    28580 => "澳门,花地玛堂区",
    28581 => "北京,昌平区",
    28582 => "浙江,杭州,萧山区",
    28583 => "四川,绵阳,涪城区",
    28585 => "北京,丰台区",
    28586 => "安徽,滁州,来安县",
    28587 => "湖南,长沙,雨花区",
    28588 => "广东,佛山,禅城区",
    28589 => "内蒙古,呼和浩特,回民区",
    28590 => "广东,深圳,坪山区",
    28591 => "广东,深圳,坪山区",
    28592 => "山东,济宁,任城区",
    28593 => "江苏,盐城,建湖县",
    28594 => "河北,廊坊,三河市",
    28595 => "浙江,宁波,镇海区",
    28596 => "安徽,合肥,蜀山区",
    28597 => "上海,浦东新区",
    28598 => "江西,九江,濂溪区",
    28599 => "山西,吕梁,兴县",
];


$start = microtime(true);
$page = 1;
$pageSize = 1000;
$lists = [];
$all_num = [];
$err = [];


$arr = json_decode($success_json, true);
foreach ($arr as $id => $item) {
    $data['area_code'] = $item['code'];
    $where['id'] = $id;
    echo $page++ . "\n";
    \Biz\model\trade\UserAddress::update($data, $where);
}


do {


    $limit = [($page - 1) * $pageSize, $pageSize];
    $where = [
        "LIMIT" => $limit,
        "area_code" => 0,
    ];
    $lists = \Biz\model\trade\UserAddress::select("*", $where);

    $data = [];

    foreach ($lists as $list) {
        try {
            $where1['id'] = $list['id'];
            $data['area_code'] = $list['city'];
            $ret = \Biz\model\trade\UserAddress::update($data, $where1);
            if ($ret->errorCode() !== '00000') {
                $err[] = $list['id'];
            } else {
                $all_num[] = $list['id'];
            }
        } catch (\Exception $e) {
            print $e->getMessage();
            exit();
        }
    }
    $page++;
} while ($lists);

$successNum = count($all_num);
$errNum = count($err);
$end = microtime(true);
$time = $end - $start;
$second = round($time, 3);
var_dump('完成时间：' . date('Y-m-d H:i:s') . '   总耗时:' . $second . '秒' . "  成功数量" . $successNum . "  失败数量" . $errNum);

